package com.commerce.constellation.adapter;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.commerce.constellation.R;


public class MySpinnerAdapter extends BaseAdapter {

    Context context; String[] strings; TypedArray ints ;

    public MySpinnerAdapter(Context context, String[] strings, TypedArray ints) {
        this.context=context;
        this.strings = strings;
        this.ints = ints;
    }

    @Override
    public int getCount() {
        return strings.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    private class ViewHolder{
        private ImageView icon;
        private TextView choice;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.text, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.icon = convertView.findViewById(R.id.text_img);
            viewHolder.choice = convertView.findViewById(R.id.text_choice);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if(ints!=null){
            viewHolder.icon.setVisibility(View.VISIBLE);
            viewHolder.icon.setImageResource(ints.getResourceId(i,0));
        }
        viewHolder.choice.setText(strings[i]);
        return convertView;
    }
}
